package zhoufu.sz.sanxiao_check.models;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.text.TextUtils;

import com.android.databinding.library.baseAdapters.BR;
import com.google.gson.annotations.Expose;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/30
 */
public class DangerModel implements Serializable {
    @Override
    public String toString() {
        return "DangerModel{" +
                "ID=" + ID +
                ", Content='" + Content + '\'' +
                ", Measure='" + Measure + '\'' +
                ", Is_Ok=" + Is_Ok +
                ", DisposeStatus=" + DisposeStatus +
                ", Item_ContentCheck=" + Item_ContentCheck +
                ", Before_Imgs=" + Before_Imgs +
                ", Applying_Imgs=" + Applying_Imgs +
                '}';
    }

    /**
     * ID : 8
     * Content : 未按要求配备灭火器或灭火器不符合配备规定
     * Measure : 必须按每30平方（含 30平方米以下）配置一个4公斤ABC干粉灭火器，一次类推
     * Is_Ok : 1
     * DisposeStatus : 0
     * Item_ContentCheck : 0
     * Before_Imgs : [{"Img":"http://120.31.131.190:8080/DlGridManageSystem/201600/06/1452066317613.jpg","Describe":"未按规定配备应急灯"}]
     * Applying_Imgs : []
     */

    private int ID;
    private String Content;
    private String Measure;
    private int Is_Ok;
    private int DisposeStatus;
    private int Item_ContentCheck;
    /**
     * Img : http://120.31.131.190:8080/DlGridManageSystem/201600/06/1452066317613.jpg
     * Describe : 未按规定配备应急灯
     */

    private List<BeforeImgsEntity> Before_Imgs;
    private List<BeforeImgsEntity> Applying_Imgs;

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getContent() {
        return Content;
    }

    public void setContent(String Content) {
        this.Content = Content;
    }

    public String getMeasure() {
        return Measure;
    }

    public void setMeasure(String Measure) {
        this.Measure = Measure;
    }

    public int getIs_Ok() {
        return Is_Ok;
    }

    public void setIs_Ok(int Is_Ok) {
        this.Is_Ok = Is_Ok;
    }

    public int getDisposeStatus() {
        return DisposeStatus;
    }

    public void setDisposeStatus(int DisposeStatus) {
        this.DisposeStatus = DisposeStatus;
    }

    public int getItem_ContentCheck() {
        return Item_ContentCheck;
    }

    public void setItem_ContentCheck(int Item_ContentCheck) {
        this.Item_ContentCheck = Item_ContentCheck;
    }

    public List<BeforeImgsEntity> getBefore_Imgs() {
        return Before_Imgs;
    }

    public void setBefore_Imgs(List<BeforeImgsEntity> Before_Imgs) {
        this.Before_Imgs = Before_Imgs;
    }

    public void setBefore_Imgs(int position, BeforeImgsEntity before_Img) {
        if (this.Before_Imgs == null || this.Before_Imgs.size() < 1) {
            ArrayList<BeforeImgsEntity> applying_imgs = new ArrayList<>();
            applying_imgs.add(null);
            setBefore_Imgs(applying_imgs);
        }
        if (this.Before_Imgs.size() == position || this.Before_Imgs.get(position) == null || TextUtils.isEmpty(this.Before_Imgs.get(position).getImg()))
            this.Before_Imgs.add(position, before_Img);
        else {
            this.Before_Imgs.set(position, before_Img);
        }
        setIs_Ok(1);
    }

    public List<BeforeImgsEntity> getApplying_Imgs() {
        return Applying_Imgs;
    }

    public void setApplying_Imgs(List<BeforeImgsEntity> Applying_Imgs) {
        this.Applying_Imgs = Applying_Imgs;
    }

    public void setApplying_Imgs(int position, BeforeImgsEntity applying_Img) {
        if (this.Applying_Imgs == null || this.Applying_Imgs.size() < 1) {
            ArrayList<BeforeImgsEntity> applying_imgs = new ArrayList<>();
            applying_imgs.add(null);
            setApplying_Imgs(applying_imgs);
        }

        if (this.Applying_Imgs.size() == position || this.Applying_Imgs.get(position) == null || TextUtils.isEmpty(this.Applying_Imgs.get(position).getImg()))
            this.Applying_Imgs.add(position, applying_Img);
        else {
            this.Applying_Imgs.set(position, applying_Img);
        }
    }

    public void delApplying_Imgs(int position) {
        if (this.Applying_Imgs != null && this.Applying_Imgs.size() > position) {
            this.Applying_Imgs.remove(position);
        }
    }

    public void delBefore_Imgs(int position) {
        if (this.Before_Imgs != null && this.Before_Imgs.size() > position) {
            this.Before_Imgs.remove(position);
        }
    }

    public static class BeforeImgsEntity extends BaseObservable implements Serializable {

        @Expose
        private String Img;
        @Expose
        private String Describe;

        public BeforeImgsEntity() {
            this.setDescribe("");
        }

        @Bindable
        public String getImg() {
            return Img;
        }

        public void setImg(String Img) {
            this.Img = Img;
            notifyPropertyChanged(BR.img);
        }

        @Bindable
        public String getDescribe() {
            return Describe;
        }

        public void setDescribe(String Describe) {
            this.Describe = Describe;
            notifyPropertyChanged(BR.describe);
        }

        @Override
        public String toString() {
            return "BeforeImgsEntity{" +
                    "Img='" + Img + '\'' +
                    ", Describe='" + Describe + '\'' +
                    '}';
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            BeforeImgsEntity that = (BeforeImgsEntity) o;

            if (Img != null ? !Img.equals(that.Img) : that.Img != null) return false;
            return Describe != null ? Describe.equals(that.Describe) : that.Describe == null;

        }

        @Override
        public int hashCode() {
            int result = Img != null ? Img.hashCode() : 0;
            result = 31 * result + (Describe != null ? Describe.hashCode() : 0);
            return result;
        }
    }

}
